package com.wteam.dragon.model.pojo.bean;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gitee.sunchenbin.mybatis.actable.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.wteam.dragon.system.basebean.bean.BaseBean;
import lombok.Data;

import java.sql.Timestamp;
import java.util.Objects;

/**
 * 用户信息
 * @Author 陈晓辉
 * @Date 2020/3/23
 */
@Data
@Table
@TableName
public class User extends BaseBean{
    @IsKey
    @IsNotNull
    @IsAutoIncrement
    @TableId(type = IdType.AUTO)
    @ColumnType(MySqlTypeConstant.BIGINT)
    @Column(comment = "自增id")
    private Long id;

    @IsNotNull
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "用户名")
    private String username;

    @IsNotNull
    @DefaultValue("无")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "用户昵称")
    private String nickName;

    @IsNotNull
    @DefaultValue("男")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "性别")
    private String sex;

    @IsNotNull
    @JsonIgnore
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "密码")
    private String password;

    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "用户头像")
    private String avatar;

    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "邮箱")
    private String email;

    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "电话")
    private String phone;

    @IsNotNull
    @DefaultValue("1")
    @ColumnType(MySqlTypeConstant.TINYINT)
    @Column(comment = "启动和禁用")
    private Boolean enabled;

    @IsNotNull
    @DefaultValue("CURRENT_TIMESTAMP")
    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @Column(comment = "最后一次更改密码时间")
    private Timestamp lastPasswordResetTime;

    @ColumnType(MySqlTypeConstant.BIGINT)
    @Column(comment = "对应角色的部门")
    private Long deptId;

    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "对应的角色id字符串（用于搜索）")
    private String roleIdStr;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        User user = (User) o;
        return Objects.equals(id, user.id) &&
                Objects.equals(username, user.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, username);
    }
}
